from bisect import bisect_left, insort


def reverse_pairs(nums):
    res = 0
    tmp = []
    for i in nums[::-1]:
        position = bisect_left(tmp, i)
        res += position
        insort(tmp, i)
    return res


if __name__ == '__main__':
    print(reverse_pairs([7, 5, 6, 4]))
